package com.cy.member.parent;

import java.awt.Dimension;
import java.awt.Point;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import com.cy.listener.ChessmanListener;
import com.cy.member.Chessboard;

/**
 * 棋子
 * @author CY
 */
public class Chessman extends JLabel {
	private static final long serialVersionUID = 1L;
	//棋子的坐标，不是像素点
	private Point site;
	//棋子的尺寸
	private static Dimension dimension = new Dimension(55,55);
	//属于哪家的棋子,true为红方，false为黑方。
	private boolean who;
	//中国象棋棋子的引用
	private ChineseChessman chineseChessman = null;
	
	public Chessman(ImageIcon image, ChineseChessman chineseChessman) {
		super(image);
		this.chineseChessman = chineseChessman;
		//为棋子添加一个监听器
		this.addMouseListener(new ChessmanListener());
	}
	
	/**
	 * 中国象棋棋子的引用
	 * @return
	 */
	public ChineseChessman getChineseChessman() {
		return chineseChessman;
	}
	
	/**
	 * 设置对中国象棋的引用
	 * @param chineseChessman
	 */
	public void setChineseChessman(ChineseChessman chineseChessman) {
		this.chineseChessman = chineseChessman;
		this.setIcon(chineseChessman.getBackground());
	}

	/**
	 * 获取棋子的尺寸
	 * @return
	 */
	public static Dimension getDimension() {
		return dimension;
	}

	/**
	 * 获取棋子的坐标
	 * @return 返回的是棋盘上的坐标，不是像素点
	 */
	public Point getSite() {
		return site;
	}

	/**
	 * 设置棋子的坐标
	 * @param site 是棋盘的坐标不是像素点
	 */
	public void setSite(Point site) {
		this.site = site;
		Point p = Chessboard.sites[site.x][site.y];
		this.setBounds(p.x - dimension.width/2, p.y - dimension.height/2, dimension.width, dimension.height);
	}

	/**
	 * 判断是哪方的棋子，true为红方，false为黑方
	 * @return
	 */
	public boolean isWho() {
		return who;
	}

	/**
	 * 设置是哪放的棋子
	 * @param who true为红方，false为黑方
	 */
	public void setWho(boolean who) {
		this.who = who;
	}
}
